<template>
    <el-upload class="import-box" ref="uploadbtn" :action="$api + apiList[props.api]"
        :headers="uploadHeaders" name="file" :show-file-list="false" :on-success="importSuccess">
        <el-button size="mini" type="danger">{{ props.txt }}</el-button>
    </el-upload>
</template>

<script setup name="UploadBtn">
import apiList from '@/api/api';
const { proxy } = getCurrentInstance();
const emit = defineEmits(['success']);
const props = defineProps({
    api: {
        required: true, type: String
    },
    txt: {
        type: String,
        default: '批量导入'
    }
});

const uploadHeaders = reactive({
  token: localStorage.getItem('token')
})

// 导入
async function importSuccess(response) {
//   if (response.code !== 0) {
//     let msg = response.message
//     if (response.data && response.data.errors) {
//       msg += response.data.errors.join('<br/>')
//     }
//     ElMessage({ type: 'error', message: msg });
//     return
//   }
  emit('success', response)
}
</script>
